<template>
  <div>
    <el-cascader :value="value" :options="list" :props="{label:'name',value:'id'}" @change="select" />
  </div>
</template>

<script>
import { getDepartmentsAPI } from '@/api/department'
import { buildTree } from '@/utils'

export default {
  name: 'SelectTree',
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      list: []
    }
  },
  async created() {
    const res = await getDepartmentsAPI()
    this.list = buildTree(res)
  },
  methods: {
    select(val) {
      this.$emit('input', val[val.length - 1])
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
